|
|
|
|
|
|
|
The OLE API has that function. It's called OLEDraw and is defined as follows in the Win32 SDK: |
|
|
|
|
|
|
|
|
WINOLEAPI OleDraw( IUnknown * pUnk, //Pointer to the view object to be drawn
DWORD dwAspect, //How the object is to be represented
HDC hdcDraw, //Device context on which to draw
LPCRECT lprcBounds //Pointer to the rectangle in which the object is drawn
); |
|
|
|
|
|
|
|
|
The pUnk parameter is defined as IUnknown *. IUnknown is the name of the interface on which all other interfaces are based. In other words, if you have a reference to a COM object, it does not matter if you are holding it in a variable declared As Object, As IUnknown, or as any other object type. It will always contain an IUnknown interface and be valid as a parameter that is declared as a pointer to an IUnknown interface. |
|
|
|
|
|
|
|
|
The remaining parameters are more straightforward: |
|
|
|
|
|
|
|
|
The dwAspect parameter allows you to specify a type of appearance. It will always be 1 for ActiveX controlsthis value instructs the control to display its contents. |
|
|
|
|
|
|
|
|
The hdcDraw parameter is a handle to a device context. This can be an API or printer device context. |
|
|
|
|
|
|
|
|
The lprcBounds parameter specifies the rectangle coordinates in which to draw the contents of the control. LP indicates a Long (far) pointer to a RECT structure. The rectangle values should be specified in logical coordinates in the system used by the device context.1 |
|
|
|
|
|
|
|
|
Figure P28-1 illustrates the design time layout of the OLEDraw sample program. This program demonstrates the display of two controls: The first is a private UserControl that displays 16 vertical color bands; the second is Microsoft's MonthView control, which is part of the Microsoft Windows Common Controls2 library. |
|
|
|
 |
|
 |
|
|
1 Chapter 7 in my book Visual Basic Programmer's Guide to the Win32 API goes into almost mind-numbing detail on how to use device contexts, the meaning of coordinate systems, and the definition of logical coordinates. For now, just assume that everything is in pixel coordinates and you'll be fine. |
|
|
|
|
|